<?php
namespace App\Listener\User;

use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Event\Annotation\Listener;

use App\Query\ConfigQuery;

/**
 * @Listener 
 */
class OrderMoneyRemainUserListener implements ListenerInterface
{
    public function listen(): array
    {
        return [
            \App\Event\User\OrderMoneyRemainUserEvent::class,
        ];
    }
    
    // 积分释放到帐户
    public function process($event)
    {
        $user = $event->user;
        $type = $event->type;
        $money = $event->money;
        $content = $event->content;
        
        if($money > 0)
        {
            // 配置
            $config = ConfigQuery::get();
            
            // 拿已释放的金额，来按比例进入用户帐号
            $user->addMoney('money', ConfigQuery::bi($config, 'order_remain_money', $money), $content, $type);
            $user->addMoney('money_make', ConfigQuery::bi($config, 'order_remain_money_make', $money), $content, $type);
            $user->addMoney('money_shop', ConfigQuery::bi($config, 'order_remain_money_shop', $money), $content, $type);
            $user->addMoney('money_point', ConfigQuery::bi($config, 'order_remain_money_point', $money), $content, $type);
            $user->addMoney('money_other', ConfigQuery::bi($config, 'order_remain_money_other', $money), $content, $type);   
        }
    }
}